#' @title 组间分类绘制热图
#' @description 利用`ComplexHeatmap`绘制热图，默认对行进行标准化，标准化范围 默认c(-1,1).
#' @param data_input 输入数据，数据框，比如表达谱
#' @param color_used 组间分类使用配色，如果为`NULL`则默认Set1配色
#' @param group_infor 分组信息，可以是单列或者多列。
#' 格式要求：样本在行名，用第一列作为配色列或者说分组依据，例如聚类分组。
#' group可以是任意分组信息
#' @param Colored_OtherInfor *logical value* or *character string* ，是否对分组信息中的其他信息进行染色，默认使用Paired调色板，
#' 如果是颜色字符串，则使用自定义颜色对其他分组信息按顺序染色，
#' @param saveplot *logical value*，是否保存图片
#' @param output_dir *character string*，文件输出路径，最好以/结尾
#' @param var_name *character string*，成图文件命名字段，字符串向量
#' @param width_used *numric*，图宽
#' @param height_used *numric*，图高
#' @param cluster_name *character string*，分组名字可以是’cluster'等字段,已弃用，默认使用group_infor第一列做为分组依据
#' @param heatmap_name *character string*，热图colorbar name，默认为NULL
#' @param DoWilcox.test *logical value*，是否对热图主体matirx 在组间使用秩和检验，检验显著性差异
#' @param show_rownames *logical value*，是否显示行名
#' @return  ggplot2对象，热图
#' @usage
#' a <- Heatmap_manul(
#'    data_input = expr[geneList, ],
#'    color_used = RColorBrewer::brewer.pal(3, "Set2"),
#'    cluster_name = 'cluster',
#'    group_infor = group_data %>% rename(group = 1),
#'    saveplot = T,
#'    output_dir = output_dir,
#'    var_name = "DLBC",
#'    width_used = 10,
#'    height_used = 12
#' )
#' @usage 表达谱示例
#' > expr[geneList, ][1:3,1:3]
#'          GSM775979 GSM775980  GSM775981
#' ATOX1    0.4598178 0.4990092 0.22533183
#' C1orf122 0.2583019 0.1842661 0.26094508
#' CENPE    0.2950682 0.3843891 0.06562005
#' @usage 分组信息示例
#' > group_data %>% rename(group = 1) %>% .[1:3,1:3]
#'           group     Age gender
#' GSM775979     A  Age<60      M
#' GSM775980     A Age>=60      F
#' GSM775981     B  Age<60      F
#' @export
#' @author *WYK*
Heatmap_manul <- function(data_input = NULL, color_used = NULL, group_infor = NULL, Colored_OtherInfor = F,
                          saveplot = T, output_dir = "./", var_name = NULL, width_used = 9, height_used = 9, heatmap_name = " ",
                          cluster_name = NULL, show_rownames = T, DoWilcox.test = F, rownames_fontsize = 7) {
    if (is.null(var_name)) {
        var_name <- paste0("_", paste0(sample(letters, 4), collapse = "", sep = ""))
    }

    if (!is.null(cluster_name)) {
        cli::cli_alert_warning(stringr::str_glue('在function {crayon::blue("Heatmap_manul")}中，参数{crayon::bold("cluster_name")} 已弃用,并且使用{crayon::bold("group_infor")}中第一列做分组依据.'))
    }
    
    suppressPackageStartupMessages(library(tidyverse))
    suppressPackageStartupMessages(library(ComplexHeatmap))
    suppressPackageStartupMessages(library(cowplot))
    suppressPackageStartupMessages(library(ggpubr))

    cluster_name <- colnames(group_infor)[1]

    sample_common <- intersect(rownames(group_infor), colnames(data_input))
    group_infor <- group_infor[sample_common, , drop = F] %>% dplyr::rename("group" = 1)
    data_input <- data_input[, sample_common]

    if (ncol(group_infor) >= 2) {
        clinical_names <- base::setdiff(colnames(group_infor), "group")
        colnames_chr <- map_chr(clinical_names, function(x) {
            # message(x)
            # x <- "HRD"
            fisher_test_res <- group_infor %>%
                dplyr::select(group, any_of(x)) %>%
                table() %>%
                fisher.test(simulate.p.value = TRUE, B = 1e7)
            fisher_p <- fisher_test_res$p.value
            pval_label <- cut(
                x = fisher_p, breaks = c(1, .05, .01, .001, .0001, 0),
                labels = c("****", "***", "**", "*", "")
            ) %>% as.character()

            x_pval_label <- paste0(x, " ", pval_label)
        })

        colnames(group_infor)[c(1:ncol(group_infor))[-which(colnames(group_infor) %in% "group")]] <- colnames_chr
    }

    # group_chara <- sort(unique(as.character(group_infor$group)))
    if (is.factor(group_infor$group)) {
        group_chara <- levels(group_infor$group)
    } else {
        group_chara <- unique(as.character(group_infor$group))
    }    

    if (is.null(color_used)) {
        col_name <- RColorBrewer::brewer.pal(8, "Set1")[1:length(group_chara)]
        col_name <- col_name[seq_along(unique(group_infor %>% pull(group)))]
    } else {
        col_name <- color_used[seq_along(unique(group_infor %>% pull('group')))]
    }

    names(col_name) <- group_chara

    if (ncol(group_infor) >= 2) {
        col_anno <- HeatmapAnnotation(
            df = group_infor, # %>% .[, "group", drop = F]
            col = list(
                group = col_name
            ),
            annotation_legend_param = list(group = list(title = c(cluster_name, base::setdiff(colnames(group_infor), "group")))),
            annotation_name_side = "right",
            annotation_label = c(cluster_name, base::setdiff(colnames(group_infor), "group"))
        )
    } else {
        col_anno <- HeatmapAnnotation(
            df = group_infor, # %>% .[, "group", drop = F]
            col = list(
                group = col_name
            ),
            annotation_name_side = "right",
            annotation_label = cluster_name
        )
    }

    if (isTRUE(Colored_OtherInfor)) {
        clinical_names <- base::setdiff(colnames(group_infor), "group")

        color_defined <- rep(RColorBrewer::brewer.pal(9, "Paired"), 10)
        # color_defined <- rep(RColorBrewer::brewer.pal(12,'Set3'),10)
        i <- 1

        color_in_heatmap <- lapply(clinical_names, function(x) {
            # x <- clinical_names[1]
            color_name <- group_infor %>%
                pull(x) %>%
                unique() %>%
                sort()

            color_used <- color_defined[i:(i + length(color_name) - 1)]
            names(color_used) <- color_name

            color_defined <- color_defined[-c(i:(i + length(color_name) - 1))]
            i <<- i + length(color_name)
            return(color_used)
        })

        names(color_in_heatmap) <- clinical_names

        color_in_heatmap$group <- col_name

        if (ncol(group_infor) >= 2) {
            col_anno <- HeatmapAnnotation(
                df = group_infor, # %>% .[, "group", drop = F]
                col = color_in_heatmap,
                annotation_legend_param = list(group = list(title = c(cluster_name, base::setdiff(colnames(group_infor), "group")))),
                annotation_name_side = "right",
                annotation_label = c(cluster_name, base::setdiff(colnames(group_infor), "group"))
            )
        } else {
            col_anno <- HeatmapAnnotation(
                df = group_infor, # %>% .[, "group", drop = F]
                col = list(
                    group = col_name
                ),
                annotation_name_side = "right",
                annotation_label = cluster_name
            )
        }
    }

    if (is.null(Colored_OtherInfor)) {
        clinical_names <- base::setdiff(colnames(group_infor), "group")

        color_defined <- rep(RColorBrewer::brewer.pal(9, "Paired"), 10)
        # color_defined <- rep(RColorBrewer::brewer.pal(12,'Set3'),10)
        i <- 1

        color_in_heatmap <- lapply(clinical_names, function(x) {
            # x <- clinical_names[1]
            color_name <- group_infor %>%
                pull(x) %>%
                unique() %>%
                sort()

            color_used <- color_defined[i:(i + length(color_name) - 1)]
            names(color_used) <- color_name

            color_defined <- color_defined[-c(i:(i + length(color_name) - 1))]
            i <<- i + length(color_name)
            return(color_used)
        })

        names(color_in_heatmap) <- clinical_names
        color_in_heatmap$group <- col_name

        if (ncol(group_infor) >= 2) {
            col_anno <- HeatmapAnnotation(
                df = group_infor, # %>% .[, "group", drop = F]
                col = color_in_heatmap,
                annotation_legend_param = list(group = list(title = c(cluster_name, base::setdiff(colnames(group_infor), "group")))),
                annotation_name_side = "right",
                annotation_label = c(cluster_name, base::setdiff(colnames(group_infor), "group"))
            )
        } else {
            col_anno <- HeatmapAnnotation(
                df = group_infor, # %>% .[, "group", drop = F]
                col = list(
                    group = col_name
                ),
                annotation_name_side = "right",
                annotation_label = cluster_name
            )
        }
    }

    if (is.character(Colored_OtherInfor)) {
        clinical_names <- base::setdiff(colnames(group_infor), "group")

        color_defined <- rep(Colored_OtherInfor, 30)
        # color_defined <- rep(RColorBrewer::brewer.pal(12,'Set3'),10)
        i <- 1

        color_in_heatmap <- lapply(clinical_names, function(x) {
            # x <- clinical_names[1]
            color_name <- group_infor %>%
                pull(x) %>%
                unique() %>%
                sort()

            color_used <- color_defined[i:(i + length(color_name) - 1)]
            names(color_used) <- color_name

            color_defined <- color_defined[-c(i:(i + length(color_name) - 1))]
            i <<- i + length(color_name)
            return(color_used)
        })

        names(color_in_heatmap) <- clinical_names

        color_in_heatmap$group <- col_name

        if (ncol(group_infor) >= 2) {
            col_anno <- HeatmapAnnotation(
                df = group_infor, # %>% .[, "group", drop = F]
                col = color_in_heatmap,
                annotation_legend_param = list(group = list(title = c(cluster_name, base::setdiff(colnames(group_infor), "group")))),
                annotation_name_side = "right",
                annotation_label = c(cluster_name, base::setdiff(colnames(group_infor), "group"))
            )
        } else {
            col_anno <- HeatmapAnnotation(
                df = group_infor, # %>% .[, "group", drop = F]
                col = list(
                    group = col_name
                ),
                annotation_name_side = "right",
                annotation_label = cluster_name
            )
        }
    }

    data_input_scaled <- t(apply(data_input, 1, function(x) scale(x, center = T, scale = T)))
    colnames(data_input_scaled) <- colnames(data_input)

    # data_input_scaled <- map_df(1:nrow(data_input), function(i) {
    #     z_scores <- (data_input[i, ] - mean(as.numeric(data_input[i, ]))) / sd(as.numeric(data_input[i, ]))
    #     return(z_scores)
    # })

    all(colnames(data_input_scaled) == group_infor %>% rownames())
    col_zscore <- circlize::colorRamp2(c(-2, 0, 2), c("#2266AC", "white", "#B2182E")) # c("#0a5aa5", "white", "firebrick3")
    # col_zscore <- circlize::colorRamp2(c(-2,0, 2), c('purple', 'black' ,'yellow')) # c("#0a5aa5", "white", "firebrick3")

    cluster_res <- Heatmap(
        matrix = data_input_scaled,
        name = heatmap_name,
        col = col_zscore,
        show_column_dend = F,
        show_column_names = F,
        show_row_names = show_rownames,
        cluster_rows = T,
        cluster_columns = T,
        show_row_dend = F,
        clustering_method_columns = "complete",
        # rect_gp = gpar(col = "white", lwd = 1),
        row_names_gp = gpar(fontsize = rownames_fontsize),
        column_title = " ",
        top_annotation = col_anno,
        column_split = group_infor %>% .[, "group", drop = F],
        border = F
        # left_annotation = row_anno,
        # row_names_side = "right"
    )

    if (isTRUE(DoWilcox.test)) {
        group_wilcoxtest_p <- map_dbl(1:nrow(data_input), function(i) {
            # i <- 1
            if (length(unique(group_infor[, 1])) == 2) {
                data_used <- data.frame(value = data_input[i, ] %>% as.numeric(), group = group_infor[match(colnames(data_input), rownames(group_infor)), "group"])
                wilcox.test_res <- wilcox.test(value ~ group, data = data_used)
                pval <- wilcox.test_res$p.value

                return(pval)
            } else {
                data_used <- data.frame(value = data_input[i, ] %>% as.numeric(), group = group_infor[match(colnames(data_input), rownames(group_infor)), "group"])
                kruskal.test_res <- kruskal.test(value ~ group, data = data_used)
                pval <- kruskal.test_res$p.value

                return(pval)
            }
        })

        names(group_wilcoxtest_p) <- rownames(data_input)

        row_anno <- rowAnnotation(
            P.val = anno_text(case_when(
                between(group_wilcoxtest_p, 0.01, 0.05) ~ "*",
                between(group_wilcoxtest_p, 0.001, 0.01) ~ "**",
                between(group_wilcoxtest_p, 0.0001, 0.001) ~ "***",
                group_wilcoxtest_p < 0.0001 ~ "****",
                group_wilcoxtest_p > 0.05 ~ " "
            ),
            gp = gpar(fontsize = 8),
            location = 1,
            just = "right"
            )
        )

        cluster_res <- Heatmap(
            matrix = data_input_scaled,
            name = heatmap_name,
            col = col_zscore,
            show_column_dend = F,
            show_column_names = F,
            show_row_names = show_rownames,
            cluster_rows = T,
            cluster_columns = T,
            show_row_dend = F,
            clustering_method_columns = "complete",
            # rect_gp = gpar(col = "white", lwd = 1),
            row_names_gp = gpar(fontsize = rownames_fontsize),
            column_title = " ",
            top_annotation = col_anno,
            column_split = group_infor %>% .[, "group", drop = F],
            border = F,
            left_annotation = row_anno
            # row_names_side = "right"
        )
    }

    # gg.cluster_res <- draw(cluster_res, merge_legend = T) %>%
    #     grid.grabExpr() %>%
    #     ggplotify::as.ggplot()

    if (saveplot) {
        dir_now <- str_glue("{output_dir}")

        if (!dir.exists(dir_now)) {
            dir.create(dir_now, recursive = T)
        } else {
            message(str_c(dir_now, " is ready."))
        }

        pdf(
            file = str_glue("{dir_now}/Figure_HeatPlot_{var_name}.pdf"),
            width = width_used, height = height_used
        )
        draw(cluster_res, merge_legend = T)
        dev.off()

        # ggsave2(
        #     filename = str_glue("{dir_now}/figure_heat_plot_ggsave_test{var_name}.pdf"),
        #     plot = gg.cluster_res, width = width_used, height = height_used
        # )
    }
    return(cluster_res)
}


#' @export
#' @details 新增功能: 自适应注释信息为分组或连续变量
#' @param data_input *data.frame*，输入数据，数据框，比如表达谱
#' @param od *character*，图片输出路径，如果为NULL 则不输出
#' @param key_color *list*，关键信息颜色自定义，比如说聚类，比如说高低风险组，可以设置多个组别的颜色信息，默认可以给NULL或者默认信息没有匹配到就自动忽略
#' @param w *numric*，图宽
#' @param h *numric*，图高
#' @param title *character*，热图title，默认NA
#' @param col_in_heat *character string*，热图颜色
#' @param group_infor 样本名在行名，特征在列的dataframe
#' @param do_rank_sum_test *boolean*,是否依据第一个分组信息对输入`data_input`的进行秩和检验
#' @param var_name *character*,保存文件字段
#' @param show_selected_row_labels *character string*，展示部分行名
Heatmap_manul_v2 <- function(
    data_input = NULL,
    key_color = list("Group" = c("High" = "#E41A1C", "low" = "#377EB8")),
    group_infor = NULL, od = NULL, title = NA,
    col_in_heat = c("#052f60", "white", "#6d021f"), rownames_fontsize = 7,
    do_rank_sum_test = T, show_rownames = T, w = 9, h = 9,
    var_name = "heat", show_selected_row_labels = NULL, ...) {

    tryCatch(library(tidyheatmaps), error = function(e) {
        # install.packages("pak"
        pak::pak("jbengler/tidyheatmaps")
    })

    if (length(which(rowSums(data_input) == 0)) > 0) {
        cli::cli_alert_warning("有加和为0的行，自动去除")
        data_input <- data_input[-which(rowSums(data_input) == 0), ]
    }

    if (any(dim(data_input) == 0)) {
        stop("data_input 输入数据为空")
    }

    stopifnot(length(unique(group_infor[[1]])) >= 2)

    library(tidyheatmaps)
    suppressMessages(library(tidyverse))
    suppressMessages(library(magrittr))

    features <- colnames(group_infor)
    df <- group_infor

    # 判断各列类型
    class_lst <- df %>% map(class)
    type_juge_index <- class_lst %>% map(~ {
        c("integer", "numeric") %in% .x %>% any()
    })
    numeric_col_name <- which(unlist(type_juge_index)) %>% names()
    character_col_name <- which(!unlist(type_juge_index)) %>% names()

    if (length(character_col_name) >= 1) {
        character_col_lst <- df %>%
            select(any_of(character_col_name)) %>%
            map(~ unique(.x) %>%
                na.omit() %>%
                as.character())

        cs <- rcartocolor::cartocolors %>%
            filter(Type != "diverging") %>%
            select(n2:n7) %>%
            unlist() %>%
            as.character() %>%
            unique()

        colors <- map(character_col_lst, ~ {
            # .x = features$Venous_Invasion
            color_used <- cs[1:length(unlist(.x))]
            cs <<- setdiff(cs, color_used)
            return(color_used)
        })

        anno_col_lst <- map2(colors, character_col_lst, ~ {
            names(.x) <- .y
            return(.x)
        })

        p_sig_label_lst <- map_chr(
            character_col_name[-1],
            ~ rstatix::chisq_test(table(df[[character_col_name[1]]], df[[.x]])) %>%
                pull(p.signif)
        )

        p_sig_label_lst <- str_replace_all(p_sig_label_lst, "ns", "")

        names(anno_col_lst)[-1] <- str_c(names(anno_col_lst)[-1], " ", p_sig_label_lst)

        colnames(df)[which(!unlist(type_juge_index))] <- names(anno_col_lst)
        features <- names(anno_col_lst)
    }

    if (length(numeric_col_name) > 0) {
        d_tmp <- expand.grid("white", RColorBrewer::brewer.pal(8, "Accent")) %>% as.matrix()

        numeric_col_lst <- seq_len(nrow(d_tmp)) %>% map(~ as.character(d_tmp[.x, ]))
        numeric_col_lst <- numeric_col_lst[seq_along(numeric_col_name)]

        if (length(unique(na.omit(df[[character_col_name[1]]]))) <= 2) {
            p_sig_label_lst <- map_chr(
                numeric_col_name,
                ~ {
                    formula_ <- as.formula(str_glue("`{.x}` ~ {character_col_name[1]}"))
                    lablel <- df %>%
                        rstatix::wilcox_test(formula_) %>%
                        rstatix::add_significance() %>%
                        pull(p.signif)
                    return(lablel)
                }
            )
        } else {
            p_sig_label_lst <- map_chr(
                numeric_col_name,
                ~ {
                    formula_ <- as.formula(str_glue("`{.x}` ~ {character_col_name[1]}"))
                    lablel <- df %>%
                        rstatix::kruskal_test(formula_) %>%
                        rstatix::add_significance() %>%
                        pull(p.signif)
                    return(lablel)
                }
            )
        }

        p_sig_label_lst <- str_replace_all(p_sig_label_lst, "ns", "")
        names(numeric_col_lst) <- str_c(numeric_col_name, " ", p_sig_label_lst)

        colnames(df)[which(unlist(type_juge_index))] <- names(numeric_col_lst)

        anno_col_lst <- c(anno_col_lst, numeric_col_lst)

        features <- c(features, names(numeric_col_lst))
    }

    if (!is.null(key_color)) {
        i <- which(names(key_color) %in% names(anno_col_lst))

        if (length(i) > 0) {
            for (j in i) {
                anno_col_lst[[names(key_color)[j]]] <- key_color[[j]]
            }
        }
    }

    data_input_long <- data_input %>%
        as.data.frame() %>%
        rownames_to_column("obs") %>%
        pivot_longer(-obs, names_to = "sample", values_to = "exprs")

    df_in_heat <- inner_join(data_input_long, df %>% rownames_to_column("sample")) %>%
        as_tibble() %>%
        arrange(get0(features[1]), exprs)

    if (isTRUE(do_rank_sum_test)) {
        obs <- rownames(data_input)

        d_in_rstest <- t(data_input) %>%
            as.data.frame() %>%
            rownames_to_column("sample") %>%
            as_tibble() %>%
            inner_join(group_infor %>% rownames_to_column("sample") %>% select(1:2))


        if (length(unique(na.omit(df[[character_col_name[1]]]))) <= 2) {
            p_sig_label_lst <- map_chr(
                obs,
                ~ {
                    formula_ <- as.formula(str_glue("`{.x}` ~ {character_col_name[1]}"))
                    lablel <- d_in_rstest %>%
                        rstatix::wilcox_test(formula_) %>%
                        rstatix::add_significance() %>%
                        pull(p.signif)

                    return(lablel)
                }
            )
        } else {
            p_sig_label_lst <- map_chr(
                obs,
                ~ {
                    formula_ <- as.formula(str_glue("`{.x}` ~ {character_col_name[1]}"))
                    lablel <- d_in_rstest %>%
                        rstatix::kruskal_test(formula_) %>%
                        rstatix::add_significance() %>%
                        pull(p.signif)
                    return(lablel)
                }
            )
        }

        obs_p_df <- tibble(p.sig = p_sig_label_lst, obs = obs) %>% arrange(p_sig_label_lst)
        df_in_heat <- df_in_heat %>% inner_join(obs_p_df)

        col <- colorRampPalette(c("steelblue", "gray90"))(5)
        names(col) <- c("****", "***", "**", "*", "ns")

        anno_col_lst$p.sig <- col[match(unique(obs_p_df$p.sig), names(col))]
        row_anno <- "p.sig"

        df_in_heat <- df_in_heat %>% arrange(get0(features[1]), get0(row_anno), exprs)

        p <- tidyheatmaps::tidy_heatmap(
            df = as.data.frame(df_in_heat),
            rows = "obs",
            columns = "sample",
            values = "exprs",
            annotation_col = features,
            annotation_row = row_anno,
            scale = "row",
            gaps_col = features[1],
            color_legend_min = -3,
            color_legend_max = 3,
            colors = col_in_heat,
            color_legend_n = 40,
            annotation_colors = anno_col_lst,
            cutree_rows = T,
            show_rownames = show_rownames,
            show_colnames = F,
            main = title,
            fontsize = rownames_fontsize,
            silent = T,
            show_selected_row_labels = show_selected_row_labels
        )
    } else {
        p <- tidyheatmaps::tidy_heatmap(
            df = as.data.frame(df_in_heat),
            rows = "obs",
            columns = "sample",
            values = "exprs",
            annotation_col = features,
            scale = "row",
            gaps_col = features[1],
            color_legend_min = -3,
            color_legend_max = 3,
            colors = col_in_heat,
            color_legend_n = 40,
            annotation_colors = anno_col_lst,
            cutree_rows = T,
            show_rownames = show_rownames,
            show_colnames = F,
            main = title,
            fontsize = rownames_fontsize,
            silent = T,
            show_selected_row_labels = show_selected_row_labels
        )
    }

    if (!is.null(od)) {
        if (is.null(var_name)) {
            var_name <- Sys.time() %>%
                as.character() %>%
                str_replace_all(":", "_") %>%
                str_replace(" ", "_") %>%
                str_replace_all("-", "_")
        }

        dir.create(od, showWarnings = F)

        pdf(str_glue("{od}/Figure_{var_name}.pdf"), width = w, height = h)
        print(p)
        dev.off()
    }

    pp <- ggplotify::as.ggplot(p)

    return(list(plot = pp, data = df_in_heat))
}

# V2测试
if (FALSE) {
    rm(list = ls())

    d <- read.delim("/Pub/Users/wangyk/project/Poroject/F230731001_OV_sc/out/bulk_part/TCGA_forest_df.tsv")

    suppressMessages(library(tidyverse))
    suppressMessages(library(magrittr))

    d2 <- tibble(sample = unique(d$sample), value = runif(352, 10, 22))
    d3 <- tibble(sample = unique(d$sample), value2 = runif(352, 1, 4))

    d <- inner_join(d, d2) %>%
        inner_join(d3) %>%
        column_to_rownames("sample")

    fs <- c("TCGA_Subtype", "Venous_Invasion", "Lymphatic_Invasion", "status", "Grade", "Stage", "value", "value2")
    exprs <- read_delim("/Pub/Users/wangyk/project/Poroject/F230731001_OV_sc/data/exprs.tsv") %>%
        as.data.frame() %>%
        column_to_rownames("gene") %>%
        .[sample(1:1e4,40), 1:200]

    # l <- list(
    #     data_input = exprs, group_infor = d %>% select(any_of(fs)),
    #     od = "/Pub/Users/wangyk/Project_wangyk/Codelib_YK/some_scr/developing",
    #     col_in_heat = c("#052f60", "white", "#6d021f"), rownames_fontsize = 6.4,
    #     do_rank_sum_test = T, show_rownames = T, w = 5, h = 6
    # )

    # iwalk(l, ~ assign(.y, .x, envir = .GlobalEnv))

    a <- Heatmap_manul_v2(
        data_input = exprs, group_infor = d %>% select(any_of(fs)),
        od = "/Pub/Users/wangyk/Project_wangyk/Codelib_YK/some_scr/tools",
        key_color = list("Group" = c("High" = "#E41A1C", "low" = "#377EB8")),
        col_in_heat = c("#052f60", "white", "#6d021f"), rownames_fontsize = 6.4,
        do_rank_sum_test = T, show_rownames = T, w = 6, h = 6,var_name = NULL
    )
}


